home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / gfx / lise2.1 / lise / src / fn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-31  |  1.7 KB  |  67 lines

  1. /* 
  2.    This program is just to perform one array operation
  3.    in order to create a spectrum file in binary float
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <math.h>
  8. #define _MAXSPCLEN 2048
  9.  
  10. float x,y,spc[_MAXSPCLEN];
  11.  
  12. main(argc,argv)
  13. int argc;
  14. char *argv[];
  15. {
  16. int n,m,i,max;
  17. char z[80],comment[80];
  18. FILE *fp;
  19.  
  20.    for(n=0;n<_MAXSPCLEN;n++) {
  21.  
  22.       x = 0.01 * (n-1024);
  23.       y = 1.0 * exp(-x*x);
  24.  
  25.       spc[n]=y;
  26.    }
  27.    fp=fopen("fnout.spc","w");
  28.    outspec(fp,spc,_MAXSPCLEN,2,"user function");
  29.    fclose(fp);
  30. }
  31.  
  32. outspec(stream,spc,max,typ1,s)
  33. char     s[];
  34. float    spc[];
  35. int      max,typ1;
  36. FILE     *stream;
  37. {
  38. unsigned char byte1,byte2,byte3,byte4;
  39. int      n,i,typ;
  40. char     c,z[80];
  41. unsigned long int m;
  42. union    fourbytes {
  43.             float                real;
  44.             long int             sig;
  45.             unsigned long int    card;
  46.          } b4;
  47.  
  48.       fputc(0,stream); fputc(2,stream);         /* write type     */
  49.       byte1=max/256 ; byte2=max-256*byte1;
  50.       byte2=max & 255 ; byte1=max/256;
  51.       fputc(byte1,stream); fputc(byte2,stream); /* write length in channels */
  52.       for(n=0;n<80;n++) fputc(s[n],stream);     /* write comment  */
  53.       for(n=1;n<=8;n++) fputc(0,stream);        /* 4 spare words  */
  54.       for(n=0;n<max;n++) {                      /* write data     */
  55.          b4.real=spc[n]; m=b4.card;
  56.                     byte1 = m / 16777216 ;
  57.                     m     = m - byte1 * 16777216 ;
  58.                     byte2 = m / 65536 ; 
  59.                     m     = m - byte2 * 65536 ;
  60.                     byte3 = m / 256 ;
  61.                     m     = m - byte3 * 256 ;
  62.                     byte4 = m ;
  63.          fputc(byte1,stream); fputc(byte2,stream);
  64.          fputc(byte3,stream); fputc(byte4,stream);
  65.       }
  66. }
  67.